I've gone through all the tutorials here and proceeded to try make my own Home Security Program for my School Proj but my issue is that the program not only runs very very slowly but it at times doesn't seem to detect the face can someone please help me?
import sys sys.path.append('/usr/local/lib/python3.4/site-packages') import numpy as np import cv2 import imutils from imutils import contours import datetime import time import dropbox
#Drawing around the detected "face" for (x, y, w, h) in faces: cv2.rectangle(frame, (x -20,y-20), (x + w + 20, y + h + 20), (255,0,0), 2) roi_color = frame[y-20:y + h + 20, x -20:x + w + 20]
#writing image of face as png in the file timestring = time.strftime("%Y_%m_%d_%H_%M_%S") face_timestr = 'face_' + timestring + '.png' cv2.imwrite(face_timestr, roi_color)
#Opening for [r]eading as [b]inary FaceFile = open(face_timestr, mode = "rb") #Reads the number of bytes of the video data = FaceFile.read()
#Setting the save location with file name SavetoLocation = '/FYP_Face_Save/'+ face_timestr SaveToLocation = str(SavetoLocation)
dbx.files_upload(data, SaveToLocation) #Close for reading and binary FaceFile.close()
#Apply the Background SubtractionMOG2 fgmask = fgbg.apply(gray) #Erode away the boundaries of the foreground object thresh = cv2.erode(fgmask, None, iterations=2)
#Set detect as none detect = None
#Find outline of a new foreground object from thresh after the erossion (_,cnts,hierarchy) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
#Draw the DateTime on the bottom left hand corner cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y %I:%M:%S%p"), (10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.35,(0,0,255), 1)
#detect is object found or not found detect = (_,cnts,hierarchy)
#if object found is detected run these codes if detect == (_,cnts,hierarchy):
#if area of object is lower than 300 ignore it for (i,c) in enumerate(cnts): if cv2.contourArea(c) < 1100: print("ignore small contours", cv2.contourArea(c)) continue
''' #Draw Rectangle around found contour object (x, y, w, h) = cv2.boundingRect(c) cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,0), 2) text = "REC" '''
#Temporary code text = "Movement Detected ... Snapping"
#Draw the text at top right hand corner cv2.putText(frame, "{}". format(text), (10,20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
#Write which window into video in this case Frame out.write(frame) #Display the following windows cv2.imshow('frame',frame) cv2.imshow('gray', gray) cv2.imshow('fgmask', fgmask)
dbx.files_upload(data, SaveToLocation) #Close for reading and binary ImageFile.close()
#if q is pressed break loop if cv2.waitKey(1) & 0xFF == ord('q'): break
#Stop recording out.release() #Kill all windows cap.release() cv2.destroyAllWindows()
#Opening for [r]eading as [b]inary VideoFile = open(timestr, mode = "rb") #Reads the number of bytes of the video data = VideoFile.read()
#Setting the save location with file name SavetoLocation = '/FYP_Video_Save/'+timestr SaveToLocation = str(SavetoLocation)
#Upload the file print("Sending to Dropbox") dbx.files_upload(data, SaveToLocation) #Close for reading and binary VideoFile.close()
You must be logged in to post. Please login or register an account.